import { GetUserInfoApi } from "@/request/api"
export default {
    namespaced: true,
    state: {
        // 用户信息
        // 做localStorage本地存储（因为一刷新，用户信息应该仍然存在）
        userInfo: JSON.parse(localStorage.getItem("edb-userInfo")) || {
            permissions: null,
            roles: null,
            user: null
        }
    },
    mutations: {
        changeUserInfo(state, payload) {
            state.userInfo = payload;
            localStorage.setItem("edb-userInfo", JSON.stringify(state.userInfo))
        }
    },
    actions: {
        async asyncChangeUserInfo({ commit }, payload) {
            let GetUserInfoApiRes = await GetUserInfoApi();
            console.log(GetUserInfoApiRes);

            if (!GetUserInfoApiRes) return
            commit("changeUserInfo", {
                permissions: GetUserInfoApiRes.permissions,
                roles: GetUserInfoApiRes.roles,
                user: GetUserInfoApiRes.user
            })
        }
    }
}
